/*
 * $Header: $
 */
package net.frankish.moviebank.front;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
import java.util.logging.Logger;

import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

import sun.swing.SwingUtilities2;

import com.sun.java.swing.SwingUtilities3;

import net.frankish.logging.FrankishLogging;
import net.frankish.moviebank.MovieBankVersion;
import net.frankish.moviebank.back.db.DerbyDatabase;
import net.frankish.moviebank.util.Configs;
import net.frankish.moviebank.util.Translator;
import net.frankish.moviebank2.front.MovieBankMenu;
import net.frankish.moviebank2.front.StatusBar;

/**
 * <p>Title: $RCSfile: Start.java,v $</p>
 * File: Start.java
 * @author Frankish
 * @version $Revision:  $
 */
public class Start {

	public static void main(String[] args){
		System.setProperty("com.sun.media.jai.disableMediaLib", "true");
		System.setProperty("net.frankish.logging.defaultconsolelogging", "true");
		try {
			UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
			FrankishLogging.getInstance().setFileHandler("net.frankish.moviebank", "./log/["+new java.sql.Date(System.currentTimeMillis())+"]MovieBank.log");
			Logger.getLogger(Start.class.getName()).warning("Starting MovieBank "+MovieBankVersion.version+ " at "+new java.sql.Time(System.currentTimeMillis()));
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (UnsupportedLookAndFeelException e) {
			e.printStackTrace();
		}
		new Start();
	}

	private Start(){
		Splash ss = new Splash();
		ss.setLocationRelativeTo(null);
		ss.setEnabled(false);
		ss.setVisible(true);
		ss.getProgressBar().startProgress("Initializing MovieBank");

		loadProperties();

		ss.getProgressBar().progress(10,"Loading Derby...");
		DerbyDatabase.start();
		ss.getProgressBar().progress(10,"Verifying MovieBank Database...");
		DerbyDatabase.create();
		ss.getProgressBar().progress(10,"Import movies from old database...");
		DerbyDatabase.convert();
		ss.getProgressBar().progress(40,"Starting MovieBank");
		MovieBankMenu.getInstance().setVisible(true);
		ss.getProgressBar().stopProgress("Enjoy your movies!");
		ss.dispose();
		ss = null;
	}

	private void loadProperties(){
		Properties props = new Properties();
		FileInputStream fis;
		try {

			fis = new FileInputStream("./conf/config.properties");
			props.load(fis);
			fis.close();
			new Configs(props);

		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

}
